package com.logic.landseaserver.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.logic.landseaserver.models.workorder.service.WorkOrderService;
import com.logic.landseaserver.service.IScheduleService;

/**
 * 
 *
 * 项目名称：system-server</br>
 * 类名称：WorkOrderTask</br>
 * 类描述：工单的定时任务</br>
 * 创建人：Crystal</br>
 * 创建时间：2017年11月4日 下午6:27:44</br>
 * @version 1.0
 *
 */
@Component
public class WorkOrderTask
{
    
    private static final Logger LOG = LoggerFactory.getLogger(WorkOrderTask.class);
    
    @Autowired
    private IScheduleService iScheduleService;
    
    @Autowired
    private WorkOrderService workOrderService;
    
    
    /**
     * 每1小时执行一次
     * 判断工单的派工情况
     */
    @Scheduled(cron = "0 0 0-23/1 * * ?") 
    public void sendMessageToManager()
    {
        try
        {
            boolean sendMsgFlag = iScheduleService.sendMsgFlag();
            if (sendMsgFlag)
            {
                LOG.info("sendMessageOfNotHandle|配置的时间内还未处理完成，发送短信给区域经理......");
                workOrderService.sendMessageOfNotHandle();
                
                LOG.info("sendMessageOfNotSent|配置的时间内未派工，发送短信给区域经理......");
                workOrderService.sendMessageOfNotSent();
                
                LOG.info("sendMessageToManager|配置的时间内未派工，发送短信给店长......");
                workOrderService.sendMessageToManager();
            }
        }
        catch (Exception e)
        {
            LOG.error("sendMessageToManager|配置的时间发送短信.", e);
        }       
    }

}